/*
============================================================================
 Name        : FlashBoxServiceSession.cpp
 Author      : 
 Version     :
 Copyright   : Your copyright notice
 Description : CFlashBoxServiceSession implementation
============================================================================
*/
#include <e32svr.h>
#include "FlashBoxServiceSession.h"
#include "clientservercommon.h"
#include "FlashBoxServiceGuard.h"
#include "FlashBoxServicePan.h"

#ifdef INHERITED_FROM_CSERVER21

CFlashBoxServiceSession::CFlashBoxServiceSession(CFlashBoxServiceGuard& aServer)
:iServer(aServer)
{
	// No implementation required
}


CFlashBoxServiceSession::~CFlashBoxServiceSession()
{
	//	iServer.DecrementSessions();
}

CFlashBoxServiceSession* CFlashBoxServiceSession::NewLC(CFlashBoxServiceGuard& aServer)
{
	CFlashBoxServiceSession* self = new (ELeave)CFlashBoxServiceSession(aServer);
	CleanupStack::PushL(self);
	self->ConstructL();
	return self;
}

CFlashBoxServiceSession* CFlashBoxServiceSession::NewL(CFlashBoxServiceGuard& aServer)
{
	CFlashBoxServiceSession* self=CFlashBoxServiceSession::NewLC(aServer);
	CleanupStack::Pop(); // self;
	return self;
}

void CFlashBoxServiceSession::ConstructL()
{
//	iServer.IncrementSessions();
}


// -----------------------------------------------------------------------------
// CFlashBoxServiceSession::ServiceL()
// Service request from client.
// -----------------------------------------------------------------------------
//
void CFlashBoxServiceSession::ServiceL( const RMessage2& aMessage )
{
	switch ( aMessage.Function() )
		{
		case EFlashBoxServSetSetting:
			//TUint8* ptr = (TUint8*) aMessage.Ptr0();
			
			//iServer.SaveSettingConfigL(*ptr);
			iServer.LoadSettingConfigL();
			break;
		
		case EFlashBoxServQuerySetting:
			iServer.LoadSettingConfigL();
			RequestSettingL(aMessage);
			break;
		case EFlashBoxLoaderExit:
			iServer.NotifyAppLoadExit();
			break;
		default:
			break;
		}
	aMessage.Complete( KErrNone );
}

// -----------------------------------------------------------------------------
// CFlashBoxServiceSession::PanicClient()
// Causes the client thread to panic.
// -----------------------------------------------------------------------------
//
void CFlashBoxServiceSession::PanicClient( const RMessagePtr2& aMessage, 
                                      TInt aPanic ) const
    {
    aMessage.Panic( KFlashBoxService,aPanic ); // Note: this panics the client thread,
                                   // not server
    }

/*
 *Handle the result of the client requesting the time.
* Gets the time and writes it back to the client synchronously.
*/
void CFlashBoxServiceSession::RequestSettingL(const RMessage2& aMessage)
{
	TUint8 setting = iServer.GetSettingStatus();
	TPtr8 ptr( reinterpret_cast<TUint8*>( &setting ), sizeof( setting ),
               sizeof( setting ) );
    
    // Write time data to the descriptor which is the first message argument
    aMessage.WriteL( 0, ptr, 0 );    
}

#endif